package com.sc.nft.entity.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sc.nft.entity.PropGift;
import com.sc.nft.enums.EquityPropsTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.RoundingMode;
import java.util.List;

@Data
public class PageAdminEquityPropsVO {

    @ApiModelProperty("id")
    private Long id;

    @ApiModelProperty("UUID")
    private String productUuid;

    @ApiModelProperty("标题")
    private String firstTitle;

    @ApiModelProperty("封面")
    private String creationContent;

    @ApiModelProperty("品牌是否可用 0:否 1:是")
    private Boolean isBrandUse;

    @ApiModelProperty("状态 1:上架中 0:下架中")
    private Boolean status;

    @ApiModelProperty("是否展示")
    private Boolean showFlag;

    @ApiModelProperty("获取规则地址")
    private String getRulesUrl;

    @ApiModelProperty("分类 : VIRTUAL_PROPS:虚拟道具 VOUCHER:盲盒兑换券")
    private EquityPropsTypeEnum typeClassify;

    @ApiModelProperty("是否过期 0:否 1:是")
    private Boolean isExpired;

    @ApiModelProperty("过期天数")
    private Integer expiredDay;

    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private String createTime;

    @ApiModelProperty("是否开启赠送")
    private Boolean isGift;

    @ApiModelProperty("时效必须大于几天")
    private Integer aging;

    @ApiModelProperty("赠送配置")
    private EquityPropsGiftVO equityPropsGifts;

    @ApiModelProperty("绑定id")
    private Long vistIn;

    @ApiModelProperty("daoId")
    private Long daoId;


    public void conversionConfiguration(List<PropGift> propGifts){
        if (CollUtil.isEmpty(propGifts)) {
            return;
        }
        if (BeanUtil.isEmpty(this.equityPropsGifts)) {
            this.equityPropsGifts=new EquityPropsGiftVO();
        }
        propGifts.forEach(propGift -> {
            if (propGift.getConsumeType().equals(1)) {
                this.equityPropsGifts.setDebrisConsume(NumberUtil.toBigDecimal(propGift.getQuantityConsume()).setScale(2, RoundingMode.DOWN).toString());
            }else if (propGift.getConsumeType().equals(2)){
                this.equityPropsGifts.setBalanceConsume(NumberUtil.toBigDecimal(propGift.getQuantityConsume()).setScale(2, RoundingMode.DOWN).toString());
            }else {
                this.equityPropsGifts.setEcologyConsume(NumberUtil.toBigDecimal(propGift.getQuantityConsume()).setScale(2, RoundingMode.DOWN).toString());
            }
        });
    }

}
